#include "../inc/sched.h"
#include <linux/init.h>
#include <linux/smp.h>
#include <linux/cpumask.h>
#include <linux/rcupdate.h>
#include <linux/sched/rt.h>
#include <linux/sched/task.h>

#define for_class_range(class, _from, _to)                         \
    for (const struct sched_class **f = _from, **t = _to, **c = f; \
         ({class = *c; c < t; }); c++)

#define for_each_class(class) \
    for_class_range(class, __sched_class_highest(), __sched_class_lowest())

static inline void init_rq(struct rq *rq)
{
    const struct sched_class *class;

    raw_spin_lock_init(&rq->__lock);
    INIT_LIST_HEAD(&rq->cfs_tasks);

    rq_attach_root_default(rq);

    for_each_class(class)
    {
        if (class->init_rq)
            class->init_rq(rq);
    }
}

static void __init init_sched_class(void)
{
    const struct sched_class *class;

    for_each_class(class)
    {
        if (class->init_class)
            class->init_class();
    }
}
